package com.bjsxt.commu1;

/**
 * 生产者线程（实际是任务）
 */
public class ProduceRunnable implements Runnable {

    private ProductFactory factory;

    public ProduceRunnable() {
    }

    public ProduceRunnable(ProductFactory factory) {
        this.factory = factory;
    }

    public ProductFactory getFactory() {
        return factory;
    }

    public void setFactory(ProductFactory factory) {
        this.factory = factory;
    }

    @Override
    public void run() {

        int i = 0;

        while (true) {

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //生成一件产品
            factory.produce("产品" + i);
            i++;
        }
    }
}
